package com.hundsun.yr.universal.p2p.ui.fragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.ColorUtils;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.gyf.barlibrary.ImmersionBar;
import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.Utils.HeaderMap;
import com.hundsun.yr.universal.library.adapter.HolderAdapter;
import com.hundsun.yr.universal.library.adapter.ViewCreatorHelper;
import com.hundsun.yr.universal.library.adapter.ViewCreatorHelper.UpdateItem;
import com.hundsun.yr.universal.library.base.BaseWebActivity;
import com.hundsun.yr.universal.library.data.HSSharedPreferences;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils;
import com.hundsun.yr.universal.library.utils.ImageLoaderHelper;
import com.hundsun.yr.universal.library.utils.MathUtils;
import com.hundsun.yr.universal.library.view.banner.BannerAutoLoopLayout;
import com.hundsun.yr.universal.library.view.hsdialog.HSDialog;
import com.hundsun.yr.universal.library.widget.HSButton;
import com.hundsun.yr.universal.library.widget.HSLabelTextView;
import com.hundsun.yr.universal.library.widget.HSLoadMoreListView;
import com.hundsun.yr.universal.library.widget.HSSwipeRefreshLayout;
import com.hundsun.yr.universal.library.widget.HSToast;
import com.hundsun.yr.universal.p2p.AdSlideSuccessBeen;
import com.hundsun.yr.universal.p2p.bean.BankAccountBeen;
import com.hundsun.yr.universal.p2p.bean.LoginBeen;
import com.hundsun.yr.universal.p2p.bean.ManeBean;
import com.hundsun.yr.universal.p2p.bean.NewsSlideShowBean;
import com.hundsun.yr.universal.p2p.bean.ProductBeen;
import com.hundsun.yr.universal.p2p.bean.StatisticsBean;
import com.hundsun.yr.universal.p2p.bean.UpdatePayPwdBeen;
import com.hundsun.yr.universal.p2p.bean.UserInfo;
import com.hundsun.yr.universal.p2p.config.Config.SPPath;
import com.hundsun.yr.universal.p2p.config.Constants;
import com.hundsun.yr.universal.p2p.config.Extras;
import com.hundsun.yr.universal.p2p.config.TaskConstants;
import com.hundsun.yr.universal.p2p.presenter.impl.InitializePresenterImpl;
import com.hundsun.yr.universal.p2p.ui.activity.InvestDetailsActivity;
import com.hundsun.yr.universal.p2p.ui.activity.LoginActivity;
import com.hundsun.yr.universal.p2p.ui.activity.MainActivity;
import com.hundsun.yr.universal.p2p.ui.activity.ManagementActivity;
import com.hundsun.yr.universal.p2p.ui.activity.MessageActivity;
import com.hundsun.yr.universal.p2p.ui.activity.MineSettingActivity;
import com.hundsun.yr.universal.p2p.ui.activity.OpenAccountBankActivity;
import com.hundsun.yr.universal.p2p.ui.activity.RechangeNewActivity;
import com.hundsun.yr.universal.p2p.ui.activity.WebActivity;
import com.hundsun.yr.universal.p2p.ui.activity.WebBindCarActivty;
import com.hundsun.yr.universal.p2p.ui.activity.WebNewsShareActivity;
import com.hundsun.yr.universal.p2p.ui.activity.WebOpenAccountActivity;
import com.hundsun.yr.universal.p2p.ui.activity.WebSetPasswordActivity;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseFragment;
import com.hundsun.yr.universal.p2p.ui.adapter.JDViewAdapter;
import com.hundsun.yr.universal.p2p.utils.BaseRequestTool2;
import com.hundsun.yr.universal.p2p.utils.CommTool;
import com.hundsun.yr.universal.p2p.utils.Logs;
import com.hundsun.yr.universal.p2p.view.base.InitializeView;
import com.hundsun.yr.universal.p2p.widget.JDAdverView;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.umeng.analytics.MobclickAgent;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @version V1.0
 * @Title: ApplyInFragment.java
 * @Description: 投资fragment
 * @date 2017-4-18 下午2:0:7
 * @author:xu.shun.zhen
 * @email:shenhj15971@hundsun.com
 * @replace author:
 * @replace date:
 */
public class HomeFragment extends BaseFragment implements InitializeView, UpdateItem<ProductBeen>, OnRefreshListener, AdapterView.OnItemClickListener,
        HSDialog.HSDialogOnItemClickListener, HSDialog.HSDialogOnDismissListener, OnClickListener, AbsListView.OnScrollListener {
    /**
     * 精品适配器
     **/
    private HolderAdapter<ProductBeen> mAdapter = null;

    /**
     * homeframent的p层逻辑
     */
    private InitializePresenterImpl mPresenter = null;
    /**
     * 轮播图布局，轮播图的布局
     **/
    private BannerAutoLoopLayout<AdSlideSuccessBeen> mBannerAutoLoopLayout = null;

    /**
     * 精品项目列表集合
     **/
    private List<ProductBeen> data = new ArrayList<ProductBeen>();
    /**
     * 用户sp
     **/
    private HSSharedPreferences hsSharedPreferences = null;

    /**
     * 下拉刷新
     **/
    private HSSwipeRefreshLayout home_hsSwipeRefreshLayout = null;
    /**
     * 默认无数据精品项目
     **/
    private ProductBeen mark = new ProductBeen();

    /**
     * 设置交易密码的提示
     */
    private HSDialog paypwdDialog = null;

    /**
     * 广告条内容
     **/
    public List<AdSlideSuccessBeen> mAdLists = new ArrayList<>();
    public List<NewsSlideShowBean> newsSlideShowBeans = new ArrayList<>();
    private String zwgt_data;

    /**
     * 总布局hslistview
     */
    private HSLoadMoreListView hslv_home_select_product = null;

    private View mHeadeView = null;
    private LayoutInflater mInflater;

    private RelativeLayout mToolbar = null;
//    private int bannerHeight;

    /**
     * 转入
     */
    private LinearLayout ll_into_money = null;

    /**
     * 邀请好友
     */
    private LinearLayout ll_sign = null;

    /**
     * 回款日历
     */
    private LinearLayout ll_debt_collection_calendar = null;
    private LinearLayout ll_message_reveal = null;

    /**
     * 绑卡弹窗
     **/
    private HSDialog dialog_bindcard = null;
    /**
     * 开户界面
     **/
    private HSDialog dialog_bindname = null;
    private PopupWindow popWindow1;
    private PopupWindow popWindow;

    /**
     * message
     */
    private ImageView iv_news_message = null;

    private JDAdverView jd_news_slide = null;
    private int mCurrentfirstVisibleItem;

    private TextView tv_home_title = null;
    private View line = null;

    /**
     * 新闻公告
     */
//    private LinearLayout ll_news_list = null;

    /**
     * 系统消息
     */
    private ImageView iv_icon_message = null;

    /**
     * 未读消息
     */
    private ImageView iv_icon_message_unread = null;
    private LayoutInflater mFooterInflater;
    private View mFooterView;

    private TextView tv_accumulative_sum_of_transaction = null;
    private TextView tv_cumulative_sum_of_transactions = null;
    private TextView tv_cumulative_number_of_services = null;

    private ImageView title_iv_icon_message;
    private ImageView title_iv_icon_message_unread;
    private RelativeLayout home_title_fl;
    private FrameLayout heade_fl;
    /**
     * 继承自BaseLazyFragment，通过fragment的声明周期，控制一个程序的流程
     */
    @Override
    protected void onFirstUserVisible() {
        // TODO Auto-generated method stub
        loadingData();
        if (((MainActivity) getActivity()).isfirstopen)
            showPopup(mToolbar);
    }

    @Override
    protected void onUserVisible() {
        // TODO Auto-generated method stub
        MobclickAgent.onPageStart("HomeFragment");
        mBannerAutoLoopLayout.startAutoScroll();
    }

    @Override
    protected void onUserInvisible() {
        // TODO Auto-generated method stub
        MobclickAgent.onPageEnd("HomeFragment");
        mBannerAutoLoopLayout.stopAutoScroll();
    }

    private void showMessage() {
        if (sharedPreferences.getBoolean(UserInfo.ISLOGIN)) {
            if (sharedPreferences.getShareProf(UserInfo.UNREAD) != null) {
                if (sharedPreferences.getShareProf(UserInfo.UNREAD).equals("0")) {
                    iv_icon_message.setVisibility(View.VISIBLE);
                    iv_icon_message_unread.setVisibility(View.INVISIBLE);
                    title_iv_icon_message.setVisibility(View.VISIBLE);
                    title_iv_icon_message_unread.setVisibility(View.INVISIBLE);
                } else {
                    iv_icon_message.setVisibility(View.INVISIBLE);
                    iv_icon_message_unread.setVisibility(View.VISIBLE);
                    title_iv_icon_message.setVisibility(View.INVISIBLE);
                    title_iv_icon_message_unread.setVisibility(View.VISIBLE);

                }
            } else {
                iv_icon_message.setVisibility(View.VISIBLE);
                iv_icon_message_unread.setVisibility(View.INVISIBLE);
                title_iv_icon_message.setVisibility(View.VISIBLE);
                title_iv_icon_message_unread.setVisibility(View.INVISIBLE);
            }
        } else {
            iv_icon_message.setVisibility(View.VISIBLE);
            iv_icon_message_unread.setVisibility(View.INVISIBLE);
            title_iv_icon_message.setVisibility(View.VISIBLE);
            title_iv_icon_message_unread.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    protected View getLoadingTargetView() {
        // TODO Auto-generated method stub
        home_hsSwipeRefreshLayout = findView(R.id.home_hsSwipeRefreshLayout);
        return home_hsSwipeRefreshLayout;
    }

    /**
     * 这个方法继承自BaseLazyFragment，BaseLazyFragment通过生命周期控制这个方法的执行顺序
     */
    @SuppressWarnings("unchecked")
    @Override
    protected void initViewsAndEvents() {
        findView();
        hsSharedPreferences = new HSSharedPreferences(mContext, SPPath.file_userLoginedInfo);

        if (mPresenter == null) {
            mPresenter = new InitializePresenterImpl(mContext, this);
        }

        /**设置viewpager或者listView时候的一个帮组类**/
        ViewCreatorHelper<ProductBeen> creatorHelper = new ViewCreatorHelper<ProductBeen>(R.layout.item_selecte_product, this);
        mAdapter = new HolderAdapter<ProductBeen>(mContext, creatorHelper.viewCreator());

        hslv_home_select_product.setAdapter(mAdapter);
        hslv_home_select_product.setOnItemClickListener(this);
        home_hsSwipeRefreshLayout.setOnRefreshListener(this);
//        hslv_home_select_product.setOnLoadMoreListener(this);
        hslv_home_select_product.setLoadMoreEnabled(false);
        //将头添加进去
        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mHeadeView = (RelativeLayout) mInflater.inflate(R.layout.head_act_main, hslv_home_select_product, false);
        hslv_home_select_product.addHeaderView(mHeadeView);
        hslv_home_select_product.setOnScrollListener(this);

        mFooterInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mFooterView = (RelativeLayout) mFooterInflater.inflate(R.layout.footer_act_main, hslv_home_select_product, false);
        hslv_home_select_product.addFooterView(mFooterView);

        //先将adapter设置好，之后在进行数据的显示，广告部分
        mBannerAutoLoopLayout = (BannerAutoLoopLayout<AdSlideSuccessBeen>) findView(mHeadeView, R.id.heade_banner_layout);
        ll_into_money = findView(mHeadeView, R.id.ll_into_money);
        ll_sign = findView(mHeadeView, R.id.ll_sign);
        ll_debt_collection_calendar = findView(mHeadeView, R.id.ll_debt_collection_calendar);
        ll_message_reveal = findView(mHeadeView, R.id.ll_message_reveal);
//        ll_news_list = findView(mHeadeView, R.id.ll_news_list);
        iv_icon_message = findView(mHeadeView, R.id.iv_icon_message);
        iv_icon_message_unread = findView(mHeadeView, R.id.iv_icon_message_unread);
        heade_fl = findView(mHeadeView,R.id.heade_fl);

        tv_accumulative_sum_of_transaction = findView(mFooterView,R.id.tv_accumulative_sum_of_transaction);
        tv_cumulative_sum_of_transactions = findView(mFooterView,R.id.tv_cumulative_sum_of_transactions);
        tv_cumulative_number_of_services = findView(mFooterView,R.id.tv_cumulative_number_of_services);

        ViewGroup.LayoutParams bannerParams = mBannerAutoLoopLayout.getLayoutParams();
        ViewGroup.LayoutParams titleBarParams = mToolbar.getLayoutParams();
        mBannerAutoLoopLayout.getLayoutParams().height = (int) (mScreenWidth * 0.57);
        mBannerAutoLoopLayout.setAdapter(R.layout.item_pager_image, new UpdateItem<AdSlideSuccessBeen>() {
            @Override
            public void refreshItem(View view, final int position, final AdSlideSuccessBeen mAdLists) {
                // TODO Auto-generated method stub
                ImageView iv_img = (ImageView) view.findViewById(R.id.image);
                String img = mAdLists.img;
                //将图片显示出来
                if (!TextUtils.isEmpty(img)) {
                    ImageLoader.getInstance().displayImage(img, iv_img, ImageLoaderHelper.getInstance(mContext).getDisplayOptions());
                }
                //设置条目的点击事件，跳转web页面
                iv_img.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (isFastDoubleClick()) {
                            return;
                        }

                        if (!NetUtils.isNetworkConnected(mContext)) {
                            showProgressToDismiss();
                            return;
                        }

                        //将数据带过去
                        Bundle bundle = new Bundle();
                        bundle.putString(BaseWebActivity.BUNDLE_KEY_URL, mAdLists.url);
                        bundle.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.more_news));
                        readyGo(WebNewsShareActivity.class, bundle);
                    }
                });
            }
        });
        mBannerAutoLoopLayout.updata(mAdLists);
        mBannerAutoLoopLayout.startAutoScroll();

        jd_news_slide = findView(mHeadeView, R.id.jd_news_slide);

        if (ImmersionBar.isSupportStatusBarDarkFont()) { //判断当前设备支不支持状态栏字体变色
            //处理状态栏字体为黑色
            ImmersionBar.with(this).titleBar(R.id.home_toolbar).statusBarDarkFont(true).flymeOSStatusBarFontColor(R.color.black).init();
        } else {
            //处理状态栏有透明度
            ImmersionBar.with(this).titleBar(R.id.home_toolbar).statusBarDarkFont(true).transparentStatusBar().init();
        }
        ll_into_money.setOnClickListener(this);
        ll_sign.setOnClickListener(this);
        ll_debt_collection_calendar.setOnClickListener(this);
        ll_message_reveal.setOnClickListener(this);
        iv_icon_message.setOnClickListener(this);
        iv_icon_message_unread.setOnClickListener(this);
        showMessage();
        automaticLogin();
    }

    private void findView() {
        hslv_home_select_product = findView(R.id.hslv_home_select_product);
        home_hsSwipeRefreshLayout = findView(R.id.home_hsSwipeRefreshLayout);
        title_iv_icon_message = findView(R.id.title_iv_icon_message);
        title_iv_icon_message.setOnClickListener(this);
        title_iv_icon_message_unread = findView(R.id.title_iv_icon_message_unread);
        title_iv_icon_message_unread.setOnClickListener(this);
        home_title_fl = findView(R.id.home_title_fl);
        mToolbar = findView(R.id.home_toolbar);
        tv_home_title = findView(R.id.tv_home_title);
        line = findView(R.id.line);
    }

    /**
     * 继承自UpdateItem，用于刷新数据
     *
     * @param view
     * @param position
     * @param entity
     */
    @Override
    public void refreshItem(View view, final int position, final ProductBeen entity) {
        LinearLayout ll_item_head = findView(view, R.id.ll_item_head);
        ImageView iv_tab = findView(view, R.id.iv_tab);
        TextView tv_more = findView(view,R.id.tv_more);

        ll_item_head.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        tv_more.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((MainActivity)(getActivity())).noScrollViewPager.setCurrentItem(1);
            }
        });

        if (position == 0) {
            ll_item_head.setVisibility(View.VISIBLE);
            iv_tab.setImageResource(R.drawable.tab_new_invest);
        } else if (position == 1) {
            ll_item_head.setVisibility(View.VISIBLE);
            iv_tab.setImageResource(R.drawable.img_recommend);
        } else {
            ll_item_head.setVisibility(View.GONE);
        }

        /**基础利率**/
        TextView tv_home_invest_rate = findView(view, R.id.tv_home_invest_rate);
        TextView add = findView(view, R.id.add);

        /**加息利率**/
        TextView tv_home_basic_debt_rate = findView(view, R.id.tv_home_basic_debt_rate);

        /**加息标签**/
        HSLabelTextView hstv_raise_interest_rate = findView(view, R.id.hstv_raise_interest_rate);

        /**活动标签**/
        HSLabelTextView hstv_raise_interest_event = findView(view, R.id.hstv_raise_interest_event);
        if (entity.add_debt_rate != null) {
            if (MathUtils.compare(entity.add_debt_rate, "0") <= 0) {
                add.setVisibility(View.GONE);
                hstv_raise_interest_rate.setVisibility(View.GONE);
                tv_home_basic_debt_rate.setVisibility(View.GONE);
                if (entity.invest_rate != null) {
                    tv_home_invest_rate.setText(CommTool.formart1(Double.valueOf(entity.invest_rate)));
                }
            } else {
                add.setVisibility(View.VISIBLE);
                hstv_raise_interest_rate.setVisibility(View.VISIBLE);
                tv_home_basic_debt_rate.setVisibility(View.VISIBLE);
                if (entity.basic_debt_rate != null) {
                    tv_home_invest_rate.setText(CommTool.formart2(Double.valueOf(entity.basic_debt_rate)));
                }

                if (entity.add_rate_msg!=null){
                    hstv_raise_interest_rate.setText(entity.add_rate_msg);
                }

                tv_home_basic_debt_rate.setText(CommTool.formart2(Double.valueOf(entity.add_debt_rate)));
            }
        } else {
            add.setVisibility(View.GONE);
            hstv_raise_interest_rate.setVisibility(View.GONE);
            tv_home_basic_debt_rate.setVisibility(View.GONE);
            if (entity.invest_rate != null) {
                tv_home_invest_rate.setText(CommTool.formartPercent1(Double.valueOf(entity.invest_rate)));
            }
        }
        if (entity.short_desc!=null&&!entity.short_desc.isEmpty()){
            hstv_raise_interest_event.setVisibility(View.VISIBLE);
            hstv_raise_interest_event.setText(entity.short_desc);
        }else {
            hstv_raise_interest_event.setVisibility(View.GONE);
        }
        /**投资期限**/
        TextView tv_home_term = findView(view, R.id.tv_home_term);
        tv_home_term.setText(entity.getTrem());

        /**剩余可投*/
        TextView tv_home_can_invest = findView(view, R.id.tv_home_can_invest);
        tv_home_can_invest.setText(getString(R.string._yuan,entity.displayChangeAmount()));

        /**进度*/
        ProgressBar hspb_home_pecent = findView(view, R.id.hspb_home_pecent);
        hspb_home_pecent.setProgress(Integer.parseInt(entity.getPercent()));

        TextView hspb_home_pecent_text = findView(view,R.id.hspb_home_pecent_text);
        hspb_home_pecent_text.setText(entity.getPercent()+"%");
        /***
         * 精选图标
         */
        HSLabelTextView hstv_selected_product = findView(view, R.id.hstv_selected_product);

        if (entity.favor_flag != null && !entity.favor_flag.isEmpty()){
            switch (entity.favor_flag){
                case "0":
                    hstv_selected_product.setVisibility(View.GONE);
                    break;
                case "1":
                    hstv_selected_product.setVisibility(View.VISIBLE);
                    break;
            }
        }

        /***
         * 新人享图标
         */
        HSLabelTextView hstv_new_exclusive = findView(view, R.id.hstv_new_exclusive);
        if (TextUtils.equals(entity.recruit_flag, "1")) {
            hstv_new_exclusive.setVisibility(View.VISIBLE);
        } else {
            hstv_new_exclusive.setVisibility(View.GONE);
        }

        /**名字**/
        TextView tv_home_name = findView(view, R.id.tv_home_name);
        tv_home_name.setText(entity.name);
    }

    /**
     * 加载数据
     */
    private void loadingData() {
        mPresenter = new InitializePresenterImpl(mContext, this);
        zwgt_data = BaseRequestTool2.getFormatedDateString();

        //精品推荐
        if (sharedPreferences.getBoolean(UserInfo.ISLOGIN)) {
            //刷新产品
            mPresenter.loadingData(TaskConstants.TASK_THREE_GOODS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_THREE_GOODS + "?top=1", Constants.
                    EVENT_REFRESH_DATA, new HashMap<String, String>(), BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test)
                    + TaskConstants.TASK_THREE_GOODS + "?top=1", sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);

            //数据披露
            mPresenter.loadingData(TaskConstants.TASK_STATISTICS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_STATISTICS, Constants.
                    EVENT_REFRESH_DATA, new HashMap<String, String>(), BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test)
                    + TaskConstants.TASK_STATISTICS, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);

            //刷新广告
            mPresenter.loadingData(TaskConstants.TASK_ADSLIDESHOW, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_ADSLIDESHOW, Constants.EVENT_REFRESH_DATA,
                    BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_index_test) + TaskConstants.TASK_ADSLIDESHOW, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.
                            getShareProf(UserInfo.TOKENID), zwgt_data), false);

            //新闻公告
            mPresenter.loadingData(TaskConstants.TASK_NEWSLIDESHOW, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_NEWSLIDESHOW, Constants.EVENT_REFRESH_DATA,
                    BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_index_test) + TaskConstants.TASK_NEWSLIDESHOW, "", ((MainActivity) getActivity()).mConfigSP.
                            getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);
        } else {
            //刷新产品
            mPresenter.loadingData(TaskConstants.TASK_THREE_GOODS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_THREE_GOODS + "?top=1", Constants.
                    EVENT_REFRESH_DATA, new HashMap<String, String>(), BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test)
                    + TaskConstants.TASK_THREE_GOODS + "?top=1", "", ((MainActivity) getActivity()).mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), true);

            //数据披露
            mPresenter.loadingData(TaskConstants.TASK_STATISTICS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_STATISTICS, Constants.
                    EVENT_REFRESH_DATA, new HashMap<String, String>(), BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test)
                    + TaskConstants.TASK_STATISTICS, "", ((MainActivity) getActivity()).mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), true);

            //刷新广告
            mPresenter.loadingData(TaskConstants.TASK_ADSLIDESHOW, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_ADSLIDESHOW, Constants.EVENT_REFRESH_DATA,
                    BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_index_test) + TaskConstants.TASK_ADSLIDESHOW, "", ((MainActivity) getActivity()).mConfigSP.
                            getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);

            //新闻公告
            mPresenter.loadingData(TaskConstants.TASK_NEWSLIDESHOW, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_NEWSLIDESHOW, Constants.EVENT_REFRESH_DATA,
                    BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_index_test) + TaskConstants.TASK_NEWSLIDESHOW, "", ((MainActivity) getActivity()).mConfigSP.
                            getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);
        }

        /**初始化内容显示**/
        mark.setDefaultMark();
        data.add(mark);
        mAdapter.update(data);

        mBannerAutoLoopLayout.updata(mAdLists);
    }

    @Override
    protected int getContentViewLayoutID() {
        // TODO Auto-generated method stub
        return R.layout.frag_home;
    }

    @Override
    protected void onEveComming(@SuppressWarnings("rawtypes") EventCenter eventCenter) {
        // TODO Auto-generated method stub
        switch (eventCenter.getEventCode()) {
            case Extras.SYSTEM_TIME_REFRESH:
                if (mAdapter != null) mAdapter.update(data);
                break;
            case Extras.INVEST_REFRESH:
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                //精品推荐
                if (sharedPreferences.getBoolean(UserInfo.ISLOGIN)) {
                    //刷新产品
                    mPresenter.loadingData(TaskConstants.TASK_THREE_GOODS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_THREE_GOODS + "?top=1", Constants.
                            EVENT_REFRESH_DATA, new HashMap<String, String>(), BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test)
                            + TaskConstants.TASK_THREE_GOODS + "?top=1", sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);

                    //数据披露
                    mPresenter.loadingData(TaskConstants.TASK_STATISTICS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_STATISTICS, Constants.
                            EVENT_REFRESH_DATA, new HashMap<String, String>(), BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test)
                            + TaskConstants.TASK_STATISTICS, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);

                    //刷新广告
                    mPresenter.loadingData(TaskConstants.TASK_ADSLIDESHOW, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_ADSLIDESHOW, Constants.EVENT_REFRESH_DATA,
                            BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_index_test) + TaskConstants.TASK_ADSLIDESHOW, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.
                                    getShareProf(UserInfo.TOKENID), zwgt_data), false);

                    //新闻公告
                    mPresenter.loadingData(TaskConstants.TASK_NEWSLIDESHOW, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_NEWSLIDESHOW, Constants.EVENT_REFRESH_DATA,
                            BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_index_test) + TaskConstants.TASK_NEWSLIDESHOW, "", ((MainActivity) getActivity()).mConfigSP.
                                    getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);
                } else {
                    //刷新产品
                    mPresenter.loadingData(TaskConstants.TASK_THREE_GOODS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_THREE_GOODS + "?top=1", Constants.
                            EVENT_REFRESH_DATA, new HashMap<String, String>(), BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test)
                            + TaskConstants.TASK_THREE_GOODS + "?top=1", sharedPreferences.getShareProf(UserInfo.USER_NO), ((MainActivity) getActivity()).mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), true);
                    //数据披露
                    mPresenter.loadingData(TaskConstants.TASK_STATISTICS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_STATISTICS, Constants.
                            EVENT_REFRESH_DATA, new HashMap<String, String>(), BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test)
                            + TaskConstants.TASK_STATISTICS, "", ((MainActivity) getActivity()).mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), true);

                    //刷新广告
                    mPresenter.loadingData(TaskConstants.TASK_ADSLIDESHOW, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_ADSLIDESHOW, Constants.EVENT_REFRESH_DATA,
                            BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_index_test) + TaskConstants.TASK_ADSLIDESHOW, sharedPreferences.getShareProf(UserInfo.USER_NO), ((MainActivity) getActivity()).mConfigSP.
                                    getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);

                    //新闻公告
                    mPresenter.loadingData(TaskConstants.TASK_NEWSLIDESHOW, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_NEWSLIDESHOW, Constants.EVENT_REFRESH_DATA,
                            BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_index_test) + TaskConstants.TASK_NEWSLIDESHOW, "", sharedPreferences.
                                    getShareProf(UserInfo.TOKENID), zwgt_data), false);
                }
                break;
            case Extras.MESSAGE:
                showMessage();
                break;
        }
    }

    @Override
    protected boolean isBindEventBusHere() {
        // TODO Auto-generated method stub
        return true;
    }


    @Override
    public void onDismiss(Object o) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onItemClick(Object o, int position) {
        // TODO Auto-generated method stub
        if ((HSDialog) o == paypwdDialog) {
            if (position != -1) {
//                zwgt_data = BaseRequestTool2.getFormatedDateString();
//                JSONObject map1 = new JSONObject();
//
//                try {
//                    map1.put("vcode", "");
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                }
//
//                JSONObject jsonParams = CommTool.getJSONParams(map1, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), zwgt_data);
//                mPresenter.loadingData(TaskConstants.TASK_SETBANKPWD, mContext.getString(R.string.root_url_test) + mContext.getString(R.string.api_user_test) + TaskConstants.TASK_SETBANKPWD, Constants.EVENT_DATA,
//                        jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, mContext.getString(R.string.api_user_test) + TaskConstants.TASK_SETBANKPWD, sharedPreferences
//                                .getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);
                readyGo(ManagementActivity.class);
            }
        } else if ((HSDialog) o == dialog_bindcard) {
            if (position != -1) {
                //readyGo(BindCardActivity.class);
                if (TextUtils.equals(sharedPreferences.getShareProf(UserInfo.IF_PAYPWD), "YES")){
                    bindCar();
                }else {
                    paypwdDialog = new HSDialog(getString(R.string.tips), getString(R.string.tips_nopaypwd),
                            getString(R.string.cancel), getString(R.string.tips_go_set), mContext, this).setCancelable(false);
                    paypwdDialog.show();
                }
            }
        } else if ((HSDialog) o == dialog_bindname) {
            if (position != -1) {
                readyGo(OpenAccountBankActivity.class);
            }
        }
    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.ll_into_money){
            Bundle bundle2 = new Bundle();
            bundle2.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.novice_guidance));
            bundle2.putString(BaseWebActivity.BUNDLE_KEY_URL, getString(R.string.root_h5_url_test) + getString(R.string.h5_guidance) + TaskConstants.TASK_NOVICE_GUIDELINES);
            bundle2.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
            bundle2.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
            readyGo(WebActivity.class, bundle2);
            return;
        }
        if (isFastDoubleClick()) {
            return;
        }

        //如果没有登陆所有的点击都是登陆按钮
        if (!sharedPreferences.getBoolean(UserInfo.ISLOGIN) && v.getId() != R.id.ll_message_reveal) {
            readyGo(LoginActivity.class);
            return;
        }

        switch (v.getId()) {
            case R.id.ll_into_money:
                Bundle bundle2 = new Bundle();
                bundle2.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.novice_guidance));
                bundle2.putString(BaseWebActivity.BUNDLE_KEY_URL, getString(R.string.root_h5_url_test) + getString(R.string.h5_guidance) + TaskConstants.TASK_NOVICE_GUIDELINES);
                bundle2.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                bundle2.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGo(WebActivity.class, bundle2);
                break;

            case R.id.ll_sign:
                ll_sign.setClickable(false);
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                JSONObject map = new JSONObject();

                JSONObject jsonParams = CommTool.getJSONParams(map, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), zwgt_data);
                mPresenter.loadingData(TaskConstants.TASK_SIGNIN, mContext.getString(R.string.root_url_test) + mContext.getString(R.string.api_user_test)
                        + TaskConstants.TASK_SIGNIN, Constants.EVENT_DATA, jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, mContext.getString(R.string.api_user_test)
                        + TaskConstants.TASK_SIGNIN, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), false);
                break;
                //回款日历
            case R.id.ll_debt_collection_calendar:
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap<String, String> hearder11 = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                        TaskConstants.TASK_CALENDAR, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
                HeaderMap headerMap11 = new HeaderMap();
                headerMap11.setMap(hearder11);
                Bundle bundle11 = new Bundle();
                bundle11.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.mine_calender));
                bundle11.putString(BaseWebActivity.BUNDLE_KEY_URL, getString(R.string.root_h5_url_test) + getString(R.string.h5_user) + TaskConstants.TASK_CALENDAR);
                bundle11.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap11);
                bundle11.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                bundle11.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGo(WebActivity.class, bundle11);
                break;

            case R.id.ll_message_reveal:
                Bundle bundle1 = new Bundle();
                bundle1.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.message_publish));
                bundle1.putString(BaseWebActivity.BUNDLE_KEY_URL, getString(R.string.root_h5_url_test) + getString(R.string.h5_index) + TaskConstants.TASK_INFORMATION);
                bundle1.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                bundle1.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGo(WebActivity.class, bundle1);
                break;
            case R.id.iv_icon_message:
            case R.id.title_iv_icon_message:
                //点击进入消息列表
                readyGo(MessageActivity.class);
                break;
            case R.id.iv_icon_message_unread:
            case R.id.title_iv_icon_message_unread:
                //点击进入消息列表
                readyGo(MessageActivity.class);
                break;
        }
    }

    @Override
    public void onRefresh() {
        zwgt_data = BaseRequestTool2.getFormatedDateString();
        if (sharedPreferences.getBoolean(UserInfo.ISLOGIN)) {
            //刷新产品
            mPresenter.loadingData(TaskConstants.TASK_THREE_GOODS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_THREE_GOODS + "?top=1", Constants.
                    EVENT_REFRESH_DATA, new HashMap<String, String>(), BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test)
                    + TaskConstants.TASK_THREE_GOODS + "?top=1", sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);

            //数据披露
            mPresenter.loadingData(TaskConstants.TASK_STATISTICS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_STATISTICS, Constants.
                    EVENT_REFRESH_DATA, new HashMap<String, String>(), BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test)
                    + TaskConstants.TASK_STATISTICS, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);

            //刷新广告
            mPresenter.loadingData(TaskConstants.TASK_ADSLIDESHOW, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_ADSLIDESHOW, Constants.EVENT_REFRESH_DATA,
                    BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_index_test) + TaskConstants.TASK_ADSLIDESHOW, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.
                            getShareProf(UserInfo.TOKENID), zwgt_data), false);

            //新闻公告
            mPresenter.loadingData(TaskConstants.TASK_NEWSLIDESHOW, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_NEWSLIDESHOW, Constants.EVENT_REFRESH_DATA,
                    BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_index_test) + TaskConstants.TASK_NEWSLIDESHOW, "", ((MainActivity) getActivity()).mConfigSP.
                            getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);

            automaticLogin();

        } else {
            //刷新产品
            mPresenter.loadingData(TaskConstants.TASK_THREE_GOODS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_THREE_GOODS + "?top=1", Constants.
                    EVENT_REFRESH_DATA, new HashMap<String, String>(), BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test)
                    + TaskConstants.TASK_THREE_GOODS + "?top=1", sharedPreferences.getShareProf(UserInfo.USER_NO), ((MainActivity) getActivity()).mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), true);

            //数据披露
            mPresenter.loadingData(TaskConstants.TASK_STATISTICS, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_STATISTICS, Constants.
                    EVENT_REFRESH_DATA, new HashMap<String, String>(), BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.api_index_test)
                    + TaskConstants.TASK_STATISTICS, "", ((MainActivity) getActivity()).mConfigSP.getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), true);

            //刷新广告
            mPresenter.loadingData(TaskConstants.TASK_ADSLIDESHOW, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_ADSLIDESHOW, Constants.EVENT_REFRESH_DATA,
                    BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_index_test) + TaskConstants.TASK_ADSLIDESHOW, sharedPreferences.getShareProf(UserInfo.USER_NO), ((MainActivity) getActivity()).mConfigSP.
                            getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);

            //新闻公告
            mPresenter.loadingData(TaskConstants.TASK_NEWSLIDESHOW, getString(R.string.root_url_test) + getString(R.string.api_index_test) + TaskConstants.TASK_NEWSLIDESHOW, Constants.EVENT_REFRESH_DATA,
                    BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_index_test) + TaskConstants.TASK_NEWSLIDESHOW, "", ((MainActivity) getActivity()).mConfigSP.
                            getShareProf(TaskConstants.TASK_CONFIG), zwgt_data), false);
        }

        zwgt_data = BaseRequestTool2.getFormatedDateString();
        mPresenter.loadingData(TaskConstants.TASK_BANK_ACCOUNT, getString(R.string.root_url_test) + getString(R.string.api_user_test) +
                TaskConstants.TASK_BANK_ACCOUNT, Constants.EVENT_BEGIN, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, getString(R.string.api_user_test)
                + TaskConstants.TASK_BANK_ACCOUNT, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), false);
    }

    /**
     * 继承自InitializeView，做网络请求成功数据的回显的
     *
     * @param task_name 任务名称
     * @param result
     * @param <T>
     */
    @Override
    public <T> void initializeViews(String task_name, T result) {
        home_hsSwipeRefreshLayout.setRefreshing(false);
        // TODO Auto-generated method stub
        switch (task_name) {
            case TaskConstants.TASK_THREE_GOODS:
                if (result == null) {
//                    btn_buy.setEnabled(false);
                    return;
                }

                //刷新精品商品
                List<ProductBeen> list;
//                if (((List<ProductBeen>) result).size() > 5) {
//                    list = ((List<ProductBeen>) result).subList(0, 5);
//                } else {
                list = ((List<ProductBeen>) result);
//                }

                //显示数据，刷新数据
                if (list != null && list.size() > 0) {
                    if (list != null) {
                        data.clear();
                        data.addAll(list);
//                        vp_home.setAdapter(mAdapter);
                    }
//                    refreshUI(0);
                    mAdapter.update(data);
                }
                break;
            case TaskConstants.TASK_ADSLIDESHOW:
                List<AdSlideSuccessBeen> list2 = (List<AdSlideSuccessBeen>) result;
                if (list2 == null) {
                    return;
                }

                if (list2 != null && list2.size() > 0) {
                    mAdLists.clear();
                    mAdLists.addAll(list2);
                    mBannerAutoLoopLayout.updata(mAdLists);
                }
                break;
            case TaskConstants.TASK_SETBANKPWD:
                if (result == null) {
                    return;
                }

                UpdatePayPwdBeen mUpdatePayPwdBeen = (UpdatePayPwdBeen) result;

                //现在做另外一种操作
                String postData = null;
                try {
                    postData = "accountId=" + URLEncoder.encode(mUpdatePayPwdBeen.data.accountId.toString(), "utf-8") + "&acqRes=" + URLEncoder.encode(mUpdatePayPwdBeen.data.acqRes.toString(), "utf-8") +
                            "&bankCode=" + URLEncoder.encode(mUpdatePayPwdBeen.data.bankCode.toString(), "utf-8") + "&channel=" + URLEncoder.encode(mUpdatePayPwdBeen.data.channel.toString(), "utf-8") +
                            "&idNo=" + URLEncoder.encode(mUpdatePayPwdBeen.data.idNo.toString(), "utf-8") + "&idType=" + URLEncoder.encode(mUpdatePayPwdBeen.data.idType.toString(), "utf-8") + "&instCode=" +
                            URLEncoder.encode(mUpdatePayPwdBeen.data.instCode.toString(), "utf-8") + "&lastSrvAuthCode=" + URLEncoder.encode(mUpdatePayPwdBeen.data.lastSrvAuthCode == null ? "" : mUpdatePayPwdBeen.data.lastSrvAuthCode.toString(), "utf-8") +
                            "&mobile=" + URLEncoder.encode(mUpdatePayPwdBeen.data.mobile.toString(), "utf-8") + "&name=" + URLEncoder.encode(mUpdatePayPwdBeen.data.name.toString(), "utf-8") + "&notifyUrl=" +
                            URLEncoder.encode(mUpdatePayPwdBeen.data.notifyUrl.toString(), "utf-8") + "&retUrl=" + URLEncoder.encode(mUpdatePayPwdBeen.data.retUrl.toString(), "utf-8") + "&seqNo=" +
                            URLEncoder.encode(mUpdatePayPwdBeen.data.seqNo.toString(), "utf-8") + "&sign=" + URLEncoder.encode(mUpdatePayPwdBeen.data.sign.toString(), "utf-8") + "&smsCode=" +
                            URLEncoder.encode(mUpdatePayPwdBeen.data.smsCode == null ? "" : mUpdatePayPwdBeen.data.smsCode.toString(), "utf-8") + "&txCode=" + URLEncoder.encode(mUpdatePayPwdBeen.data.txCode.toString(), "utf-8") +
                            "&txDate=" + URLEncoder.encode(mUpdatePayPwdBeen.data.txDate.toString(), "utf-8") + "&txTime=" + URLEncoder.encode(mUpdatePayPwdBeen.data.txTime.toString(), "utf-8") + "&version=" +
                            URLEncoder.encode(mUpdatePayPwdBeen.data.version.toString(), "utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                    Logs.e("e.toString: " + e.toString());
                }

                Bundle bundle = new Bundle();
                bundle.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.set_paywd));
                bundle.putString(BaseWebActivity.BUNDLE_KEY_URL, mUpdatePayPwdBeen.url);
                bundle.putString(BaseWebActivity.BUNDLE_KEY_PARAMS, postData);
                bundle.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.POSTDATA.getIntValue());
                bundle.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGo(WebSetPasswordActivity.class, bundle);
                break;

            case TaskConstants.TASK_NEWSLIDESHOW:
                if (result == null) {
                    return;
                }
                //刷新精品商品
                List<NewsSlideShowBean> newsSlideShowBeans = (List<NewsSlideShowBean>) result;
                //显示数据，刷新数据
                if (newsSlideShowBeans != null && newsSlideShowBeans.size() > 0) {
                    if (newsSlideShowBeans != null) {
                        this.newsSlideShowBeans.clear();
                        this.newsSlideShowBeans.addAll(newsSlideShowBeans);
//                        vp_home.setAdapter(mAdapter);
                    }

                    JDViewAdapter adapter = new JDViewAdapter(this.newsSlideShowBeans, mContext);
//                    adapter.setItem();
                    jd_news_slide.setAdapter(adapter);
                    jd_news_slide.stop();
                    //开启线程滚动
                    jd_news_slide.start();
                }
                break;

            case TaskConstants.TASK_SIGNIN:
                ll_sign.setClickable(true);
                switch (result.toString()) {
                    case Constants.REQUESTCODE_000000:
                        showToast(getString(R.string.sign_success));
                        showPopup(mToolbar, false);
                        break;
                    case Constants.REQUESTCODE_200709:
                        showToast(getString(R.string.signed));
                        showPopup(mToolbar, true);
                        break;
                }
                break;
            case TaskConstants.TASK_LOGINSILENT:
                LoginBeen loginBeen = (LoginBeen) data;
                Log.e("loginBeen",loginBeen.is_lender);
               // showMessage();
                break;

            case TaskConstants.TASK_STATISTICS:
                StatisticsBean statisticsBean = (StatisticsBean) result;
                tv_accumulative_sum_of_transaction.setText(CommTool.moneyOneThousands(statisticsBean.amount + ""));
                tv_cumulative_sum_of_transactions.setText(statisticsBean.num + "笔");
                tv_cumulative_number_of_services.setText(statisticsBean.people + "人");
                break;
            case TaskConstants.TASK_CARDBIND:
                Gson gson =new Gson();
                ManeBean maneBean = gson.fromJson(String.valueOf(data), ManeBean.class);
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap<String, String> hearder1 = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                        "bindcardpagerst", sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
                HeaderMap headerMap1 = new HeaderMap();
                headerMap1.setMap(hearder1);
                Bundle bundle1 = new Bundle();
                bundle1.putString(BaseWebActivity.BUNDLE_KEY_URL, maneBean.getHtml());
                bundle1.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap1);
                bundle1.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.DATA.getIntValue());
                readyGo(WebOpenAccountActivity.class, bundle1);
                break;
            case TaskConstants.TASK_BANK_ACCOUNT:
                //查询托管账户信息，更新ui
                BankAccountBeen bankAccountBeen = (BankAccountBeen) result;
                //保存余额信息
//                sharedPreferences.putShareProf(UserInfo.CAN_USE_MONEY, bankAccountBeen.availBal);

                //对江西银行卡信息进行显示
                if (!bankAccountBeen.depository_bank_no.isEmpty()) {//如果返回有银行卡信息，则将银行卡信息保存并且显示银行卡
                    //将获得的银行卡信息保存
                    sharedPreferences.putShareProf(UserInfo.JX_ACCOUNT_NO, bankAccountBeen.depository_bank_no);
                }

                //如果获取了用户的银行卡信息就将其绑定
                /**存储开户信息**/
                if (bankAccountBeen.depository_bank_no != null && !bankAccountBeen.depository_bank_no.isEmpty()) {
                    sharedPreferences.putShareProf(UserInfo.JIANGXI_BANKCARD, bankAccountBeen.depository_bank_no);
                    sharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "YES");
                } else {
                    sharedPreferences.putShareProf(UserInfo.IF_ACCOUNT, "NO");
                }

                /**存储绑卡信息**/
                if (bankAccountBeen.bankCard != null && !bankAccountBeen.bankCard.isEmpty() && bankAccountBeen.bankName != null && !bankAccountBeen.bankName.isEmpty()) {
                    sharedPreferences.putShareProf(UserInfo.BANKCARD, bankAccountBeen.bankCard);
                    sharedPreferences.putShareProf(UserInfo.BANKCARDNAME, bankAccountBeen.bankName);

                    sharedPreferences.putShareProf(UserInfo.IF_BINDCARD, "YES");
                } else {
                    sharedPreferences.putShareProf(UserInfo.IF_BINDCARD, "NO");
                }

                if (bankAccountBeen.true_name != null && !bankAccountBeen.true_name.isEmpty()){
                    sharedPreferences.putShareProf(UserInfo.REAL_USER_NAME, bankAccountBeen.true_name);
                }

                /**
                 * 绑定身份证
                 */
                if (bankAccountBeen.cert_no != null && !bankAccountBeen.cert_no.isEmpty()){
                    sharedPreferences.putShareProf(UserInfo.CERT_NO, bankAccountBeen.cert_no);
                }

                /**保存登陆手机号**/
                //保存手机号码
                if (bankAccountBeen.phone != null && !bankAccountBeen.phone.isEmpty()) {
                    sharedPreferences.putShareProf(UserInfo.MOBILE, bankAccountBeen.phone);
                }

/*            *//**保存用户交易密码设置状态**/
                if (bankAccountBeen.set_paypwd_flag != null && !bankAccountBeen.set_paypwd_flag.isEmpty()) {
                    if (TextUtils.equals(bankAccountBeen.set_paypwd_flag, "1")) {
                        //已经设置交易密码
                        sharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "YES");
                    } else {
                        sharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "NO");
                    }
                } else {
                    sharedPreferences.putShareProf(UserInfo.IF_PAYPWD, "NO");
                }

                /**保存可用余额**/
                if (bankAccountBeen.availBal != null && !bankAccountBeen.availBal.isEmpty()) {
                    sharedPreferences.putShareProf(UserInfo.CAN_USE_MONEY, bankAccountBeen.availBal);
                }

                //保存用户vip等级
                if (bankAccountBeen.vip != null && !bankAccountBeen.vip.isEmpty()) {
                    sharedPreferences.putShareProf(UserInfo.VIPLEVEL, bankAccountBeen.vip);
                }

                break;
        }
    }

    /**
     * 继承自InitializeView，网络请求失败，加载的数据，这边的处理是重新刷新
     *
     * @param task_name 任务名称
     * @param data
     * @param <T>
     */
    @Override
    public <T> void initializeError(String task_name, T data) {
        // TODO Auto-generated method stub
        home_hsSwipeRefreshLayout.setRefreshing(false);
        ll_sign.setClickable(true);
    }

    private void showProgressToDismiss() {
        showProgress("");
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                closeProgress();
            }
        }, 2000);
    }

    /**
     * 防止按钮连续点击
     */
    private static long lastClickTime;

    public static boolean isFastDoubleClick() {
        long time = System.currentTimeMillis();
        if (time - lastClickTime < 500) {
            return true;
        }
        lastClickTime = time;
        return false;
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if (keyCode == event.KEYCODE_BACK) {
            if (paypwdDialog != null && paypwdDialog.isShowing()) {
                paypwdDialog.dismiss();
                return true;
            } else {
                return false;
            }
        }
        return false;
    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (isFastDoubleClick()) {
            return;
        }
        // TODO Auto-generated method stub
        if (position > data.size() || position <= 0) return;
        if (!sharedPreferences.getBoolean(UserInfo.ISLOGIN)) {
            //如果没有登陆跳转到登陆页面
            Intent intent = new Intent(mContext, LoginActivity.class);
            mContext.startActivity(intent);
            showToast(R.string.tips_login);
            return;
        }

        //将id带过去用于网络请求，显示详情页面的信息
        Bundle bundle = new Bundle();
        bundle.putSerializable(Extras.DATA, data.get(position - 1));
        readyGo(InvestDetailsActivity.class, bundle);
    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {

    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        mCurrentfirstVisibleItem = firstVisibleItem;
        View firstView = view.getChildAt(0);
        if (null != firstView) {
            ItemRecod itemRecord = (ItemRecod) recordSp.get(firstVisibleItem);
            if (null == itemRecord) {
                itemRecord = new ItemRecod();
            }
            itemRecord.height = firstView.getHeight();
            itemRecord.top = firstView.getTop();
            recordSp.append(firstVisibleItem, itemRecord);
            int totalDy = getScrollY();//滚动距离

            //在此进行你需要的操作//TODO

            if (totalDy <= 300) {
                mToolbar.setVisibility(View.VISIBLE);
                float alpha = (float) totalDy / 300;
                mToolbar.setBackgroundColor(ColorUtils.blendARGB(Color.TRANSPARENT
                        , ContextCompat.getColor(mContext, R.color.white), alpha));

                tv_home_title.setTextColor(ColorUtils.blendARGB(Color.TRANSPARENT
                        , ContextCompat.getColor(mContext, R.color.black), alpha));

                line.setBackgroundColor(ColorUtils.blendARGB(Color.TRANSPARENT
                        , ContextCompat.getColor(mContext, R.color.background), alpha));
                /*home_title_fl.setVisibility(View.GONE);
                heade_fl.setVisibility(View.VISIBLE);*/

            } else {
                mToolbar.setVisibility(View.VISIBLE);
                mToolbar.setBackgroundColor(ColorUtils.blendARGB(Color.TRANSPARENT
                        , ContextCompat.getColor(mContext, R.color.white), 1));

                tv_home_title.setTextColor(ColorUtils.blendARGB(Color.TRANSPARENT
                        , ContextCompat.getColor(mContext, R.color.black), 1));

                line.setBackgroundColor(ColorUtils.blendARGB(Color.TRANSPARENT
                        , ContextCompat.getColor(mContext, R.color.background), 1));
                /*home_title_fl.setVisibility(View.VISIBLE);
                heade_fl.setVisibility(View.GONE);*/
            }

        }
//        if (visibleItemCount >= 5){
//            mToolbar.setVisibility(View.VISIBLE);
//        } else {
//            mToolbar.setVisibility(View.INVISIBLE);
//        }
    }

    private SparseArray recordSp = new SparseArray(0);

    private int getScrollY() {
        int height = 0;
        for (int i = 0; i < mCurrentfirstVisibleItem; i++) {
            ItemRecod itemRecod = (ItemRecod) recordSp.get(i);
            if (itemRecod != null) {
                height += itemRecod.height;
            }

        }
        ItemRecod itemRecod = (ItemRecod) recordSp.get(mCurrentfirstVisibleItem);
        if (null == itemRecod) {
            itemRecod = new ItemRecod();
        }
        return height - itemRecod.top;
    }

    class ItemRecod {
        int height = 0;
        int top = 0;
    }

    /**
     * 创建PopupWindow对象
     *
     * @param parent
     */
    @SuppressLint("InflateParams")
    private void showPopup(View parent) {
        backgroundAlpha((float) 0.5);
        View view = null;
        LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.pop_open_account, null);

        ImageView iv_close_pop = findView(view, R.id.iv_close_pop);
        ImageView iv_back_pop = findView(view, R.id.iv_back_pop);
        HSButton btn_go_to_openaccount = findView(view, R.id.btn_go_to_openaccount);

        iv_close_pop.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow1.dismiss();
            }
        });

        iv_back_pop.setImageResource(R.drawable.back_go_to_register);

        btn_go_to_openaccount.setText(R.string.dialog_go_to_register);
        btn_go_to_openaccount.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow1.dismiss();
                Bundle bundle = new Bundle();
                bundle.putBoolean("REGISTER_FIRST", true);
                readyGo(LoginActivity.class, bundle);
            }
        });


        popWindow1 = new PopupWindow(view, LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT, true);


        // 设置背景，这个是为了点击“返回Back”也能使其消失，并且并不会影响你的背景
        popWindow1.setBackgroundDrawable(getResources().getDrawable(R.color.transparent_66));
        ColorDrawable cd = new ColorDrawable(Color.TRANSPARENT);
        popWindow1.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        //popupwindow弹出时的动画
        popWindow1.setAnimationStyle(R.style.project_pop_style);
        popWindow1.setClippingEnabled(false);
        //软键盘不会挡着popupwindow
        popWindow1.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //监听菜单的关闭事件
        popWindow1.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                backgroundAlpha(1f);
            }
        });


        popWindow1.setTouchable(true);
        // 使其聚集 ，要想监听菜单里控件的事件就必须要调用此方法
        popWindow1.setFocusable(true);
        // 设置允许在外点击消失
        popWindow1.setOutsideTouchable(true);
//        //监听触屏事件
        popWindow1.setTouchInterceptor(new View.OnTouchListener() {
            @SuppressLint("ClickableViewAccessibility")
            public boolean onTouch(View view, MotionEvent event) {
                return false;
            }
        });
        popWindow1.showAtLocation(parent, Gravity.CENTER, 0, 0);
    }

    private void showPopup(View parent, boolean isSign) {
        backgroundAlpha((float) 0.5);
        View view = null;
        LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.pop_sign_red_packet, null);

        HSButton btn_to_red_packet = findView(view, R.id.btn_to_red_packet);
        ImageView iv_red_packet_close = findView(view, R.id.iv_red_packet_close);
        TextView tv_sign_status = findView(view, R.id.tv_sign_status);
        TextView tv_sign_date = findView(view, R.id.tv_sign_date);

        if (isSign) {
            tv_sign_status.setText(getString(R.string.signed_today_success));
            tv_sign_date.setText("");
        } else {
            tv_sign_status.setText(getString(R.string.sign_success));
            tv_sign_date.setText("获取0.05元");
        }

        btn_to_red_packet.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                popWindow.dismiss();
                //进入查看红包
                zwgt_data = BaseRequestTool2.getFormatedDateString();
                HashMap<String, String> hearder7 = BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_GET, mContext.getString(R.string.h5_user) +
                        TaskConstants.TASK_MYDISCOUNT, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data);
                HeaderMap headerMap7 = new HeaderMap();
                headerMap7.setMap(hearder7);
                Bundle bundle7 = new Bundle();
                bundle7.putString(BaseWebActivity.BUNDLE_KEY_TITLE, getString(R.string.mine_bonus));
                bundle7.putString(BaseWebActivity.BUNDLE_KEY_URL, getString(R.string.root_h5_url_test) + getString(R.string.h5_user) + TaskConstants.TASK_MYDISCOUNT);
                bundle7.putSerializable(BaseWebActivity.BUNDLE_KEY_HEADER, headerMap7);
                bundle7.putInt(BaseWebActivity.BUNDLE_KEY_LOADTYPE, BaseWebActivity.LoadType.HTTP.getIntValue());
                bundle7.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                readyGo(WebActivity.class, bundle7);
            }
        });

        iv_red_packet_close.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });

        popWindow = new PopupWindow(view, LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT, true);

        // 设置背景，这个是为了点击“返回Back”也能使其消失，并且并不会影响你的背景
        popWindow.setBackgroundDrawable(getResources().getDrawable(R.color.transparent_66));
        ColorDrawable cd = new ColorDrawable(Color.TRANSPARENT);
        popWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        //popupwindow弹出时的动画
        popWindow.setAnimationStyle(R.style.project_pop_style);
        popWindow.setClippingEnabled(false);
        //软键盘不会挡着popupwindow
        popWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //监听菜单的关闭事件
        popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                backgroundAlpha(1f);
            }
        });


        popWindow.setTouchable(true);
        // 使其聚集 ，要想监听菜单里控件的事件就必须要调用此方法
        popWindow.setFocusable(true);
        // 设置允许在外点击消失
        popWindow.setOutsideTouchable(true);
//        //监听触屏事件
        popWindow.setTouchInterceptor(new View.OnTouchListener() {
            @SuppressLint("ClickableViewAccessibility")
            public boolean onTouch(View view, MotionEvent event) {
                return false;
            }
        });
        popWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
    }

    /**
     * 设置添加屏幕的背景透明度
     *
     * @param bgAlpha
     */
    public void backgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes();
        lp.alpha = bgAlpha; //0.0-1.0
        getActivity().getWindow().setAttributes(lp);
    }

    private void automaticLogin() {
        if (sharedPreferences.getShareProf(UserInfo.TOKENID) != null && !sharedPreferences.getShareProf(UserInfo.TOKENID).isEmpty()) {
            zwgt_data = BaseRequestTool2.getFormatedDateString();
            JSONObject map = new JSONObject();
            try {
                map.put("token", sharedPreferences.getShareProf(UserInfo.TOKENID));
            } catch (JSONException e) {
                e.printStackTrace();
            }

            JSONObject jsonParams = CommTool.getJSONParams(map, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), zwgt_data);
            mPresenter.loadingData(TaskConstants.TASK_LOGINSILENT, mContext.getString(R.string.root_url_test) + mContext.getString(R.string.api_index_test)
                    + TaskConstants.TASK_LOGINSILENT, Constants.EVENT_DATA, jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, mContext.getString(R.string.api_index_test)
                    + TaskConstants.TASK_LOGINSILENT, sharedPreferences.getShareProf(UserInfo.USER_NO), sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);
        }
    }

    private void bindCar(){
        //绑定银行卡
        String zwgt_data = BaseRequestTool2.getFormatedDateString();
        JSONObject map = new JSONObject();
        JSONObject jsonParams = CommTool.getJSONParams(map, sharedPreferences.getShareProf(UserInfo.TOKENID).substring(0, 24), zwgt_data);
        mPresenter.loadingData(TaskConstants.TASK_CARDBIND, getString(R.string.root_url_test) + getString(R.string.api_user_test) + TaskConstants.TASK_CARDBIND,
                Constants.EVENT_DATA,jsonParams, BaseRequestTool2.getHearder(mContext, TaskConstants.TASK_POST, getString(R.string.api_user_test) + TaskConstants.TASK_CARDBIND,
                        sharedPreferences.getShareProf(UserInfo.USER_NO),
                        sharedPreferences.getShareProf(UserInfo.TOKENID), zwgt_data), true);
    }
}
